home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
TPREAL2.ARJ
/
TPREAL1.DOC
< prev
Wrap
Text File
|
1992-03-13
|
4KB
|
71 lines
Improved Floating Point Subroutines for Turbo Pascal
This software package is meant to be a superior alternative for Turbo
Pascal's built in floating point library for the "real" format. Programs
using the "real" format for intensive numeric computation can benefit
from this package when run on a computer without a numeric co-processor.
To use this package, you should have Turbo Pascal version 4.0 or later.
The library is in the form of a TPU file. To use this library, you need
to add the statement "uses rlib;" at the beginning of your program. The
library consists of subroutines for floating point multiplication,
division, sqrt, sin, cos, arctan, exp and ln. To get the equivalent of
x*y in your program, just substitute _mul(x,y). Similarly, to get x/y,
use _div(x,y).(x and y can themselves be expressions instead of
variables.) To get the other functions, just add an underscore before
the equivalent TP definition. For example, _sin(x) for sin(x).
Creating RLIB.TPU
Since TPU files created using different versions of Turbo Pascal are,
in general, incompatible with one another, the TPU file has to be
compiled using your current version of Turbo Pascal. To create RLIB.TPU,
compile RLIB.PAS to disk, making sure that the correct path to the OBJ
files which come in this package is specified in the compiler. This
package also comes with a program 'TEST.PAS' which can be used to compare
this package with Turbo Pascal's. The average speed improvement ranges from
20% for multiplication to about 1200% for sqrt. The "Savage" option is
a benchmark to test the accuracy of the routines. The lower the residual
error, the better is the accuracy of the routines. This package can be
seen to be superior than Turbo Pascal's by running the "Savage" option.
Error Handling
When a floating point error occurs, the type of error and the address
where the error occured in the main program are displayed and the
program is halted. Errors are of three types-division by zero, overflow,
and illegal function call. If you want, you can write your own error
handling routine. The rules are:
1. The global pointer variable matherrptr declared in RLIB.TPU should
be set to the address of your routine at the beginning of the program.
Eg., matherrptr:=@myerrproc;
2. The error handling routine should be compiled with the far option
turned on.({$F+})
3. The input parameters to the error handling routine are an integer
and a pointer in that order. The integer contains the type of floating
point error (1-division by zero, 2-overflow, 3-illegal function call)
and the pointer contains the address of the main program from where the
call was made. Even if you don't use these parameters, they should appear
in the procedure declaration. Also, do not use "var" in the input
declaration. A typical error handling routine might look like:
procedure myerrproc(typeoferror:integer;erroraddr:pointer);
begin
writeln('Its debugging time!');
end;
Failure to follow the above rules might result in a crashed program!
The error handler can pass control back instead of halting. In that case,
the value returned by the floating point subroutine would be 1.7E38 in
magnitude, the sign depending on the input variables to the routine.
Information and Correspondence
The author hopes that this package would be useful to many. Any
suggestions and questions regarding this package are welcome. Please
e-mail your comments to shankar@ecn.purdue.edu. If you find this software
highly useful, please send a check for any amount you wish payable to:
Shankar Ramakrishnan
253 Sheetz St. #9
West Lafayette,IN 47906
Shankar Ramakrishnan
March 5 1992